//index.js

//获取应用实例
const app = getApp()

wx.setBackgroundTextStyle({
  textStyle: 'dark' // 下拉背景字体、loading 图的样式为dark
})

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    audio: {
      poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
      name: '此时此刻',
      author: '许巍',
      src: 'https://ex-sycdn.kuwo.cn/b2f1cab73bd44452a09209b60fc403b9/5f07ce7c/resource/n2/31/4/1514345542.mp3',
    },
    playList:[{
      poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
      name: '此时此刻',
      author: '许巍',
      src: 'https://ex-sycdn.kuwo.cn/b2f1cab73bd44452a09209b60fc403b9/5f07ce7c/resource/n2/31/4/1514345542.mp3',
    },
    {
      poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
      name: '此时此刻2',
      author: '许巍2',
      src: 'https://ex-sycdn.kuwo.cn/b2f1cab73bd44452a09209b60fc403b9/5f07ce7c/resource/n2/31/4/1514345542.mp3',
    }
  ]
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
    // 提示
    if (this.hasUserInfo) {
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      })
    }
  },
  onPullDownRefresh: function () {
    console.log('下拉成功')
  },
  tabChange(e) {
    console.log('tab change', e)
  },
  onReady: function () {
    // 设置页面导航条颜色
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#FF69B4',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    this.audioCtx = wx.createAudioContext('Audio')
  },
  btnPlay: function () {
    this.setData({
      is_play_bool: true
    })
  }, btnPause: function () {
    this.setData({
      is_play_bool: false
    })
  },
  audioPlay() { // 播放
    this.audioCtx.play()
  },
  audioPause() { // 暂停
    this.audioCtx.pause()
  },
  download:function(e){
    // id = e.currentTarget.dataset.id
    console.log('下载')
  },
  play_btn:function(e){
    //播放选择
    // id = e.currentTarget.dataset.data_id
    // data = this.data.playList[1]
    console.log("播放")

  }
})